﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class ListMember : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (Session["enterprise_bid"] != null)
            {
                int bid = Convert.ToInt32(Session["enterprise_bid"]);
                lcmyjobs.BLL.enterprise_level elm = new BLL.enterprise_level();

                DataSet ds = elm.GetLevelById(bid);
                int cnt = ds.Tables[0].Rows.Count;

                this.lbl_addlevel.Text = "";
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < cnt; i++)
                    {
                        if (Convert.ToInt32(ds.Tables[0].Rows[i]["status"]) == 0)
                        {
                            this.lbn_addlevel.Visible = false;
                            this.lbl_addlevel.Text = "申请单位升级成功！请等待管理员审核！";
                            break;
                        }
                    }
                }
                
            }

            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—单位升级：单位升级  {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_bid"] != null)
                {
                    int enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);
                    Bind(enterprise_bid);

                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }
            }

        }

        private void Bind(int enterprise_bid)
        {
            lcmyjobs.BLL.enterprise_member em = new BLL.enterprise_member();

            DataSet ds = em.GetList(enterprise_bid);

            this.lbl_title.Text = " " + ds.Tables[1].Rows[0][0].ToString();

            this.gv_memeber.DataSource = ds;
            this.gv_memeber.DataBind();


        }



        protected void gv_memeber_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //RadioButton r = e.Row.FindControl("rdo_button") as RadioButton;

                //r.Attributes.Add("onclick", "judge(this)");
                //if (r.Text == "-1天")
                //{
                //    r.Visible = false;
                //    Label lb = e.Row.FindControl("lbl_sy") as Label;
                //    lb.Visible = true;
                //    lb.Text = "不限";
                //}
            }
        }

        public string GetString(string str)
        {
            if (str == "0")
            {
                return "不限";
            }
            else
            {
                return str;
            }
        }

        protected void gv_memeber_DataBound(object sender, EventArgs e)
        {
            lcmyjobs.BLL.Tools.UnitCell(this.gv_memeber, 0);
        }
        //申请升级
        protected void lbn_addlevel_Click(object sender, EventArgs e)
        {
            string selectedValue = Request.Form["myradio"];

            int enterprise_mid = Convert.ToInt32(selectedValue);

            if (!string.IsNullOrEmpty(selectedValue))
            {
                if (Session["enterprise_bid"] != null)
                {
                    int enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                    lcmyjobs.Model.enterprise_level el = new Model.enterprise_level();

                    el.enterprise_bid = enterprise_bid;
                    el.enterprise_mid = enterprise_mid;
                    el.submittime = DateTime.Now;
                    el.status = 0;//0、未审核，1、审核通过

                    lcmyjobs.BLL.enterprise_level elm = new BLL.enterprise_level();

                    if (elm.Add(el) > 0)
                    {
                        Maticsoft.Common.MessageBox.Show(this, "申请升级成功！");
                    }

                   
                    DataSet ds = elm.GetLevelById(enterprise_bid);
                    int cnt = ds.Tables[0].Rows.Count;

                    this.lbl_addlevel.Text = "";
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < cnt; i++)
                        {
                            if (Convert.ToInt32(ds.Tables[0].Rows[i]["status"]) == 0)
                            {
                                this.lbn_addlevel.Visible = false;
                                this.lbl_addlevel.Text = "申请单位升级成功！请等待管理员审核！";
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请选择申请级别！", "ListMember.html");
            }



        }
    }
}